package bill.study.concurrency.confinement;

import java.util.Random;

public class UserThreadLocalTester {

	public static void main(String args[]) {

		// Each thread increments counter
		// Displays variable info
		// And sleeps for the random amount of time
		// Before displaying info again
		// For random number generation

		Runnable runner = new Runnable() {
			public void run() {
				for (int i = 0; i < 10; i++) {
					User user = UserHolder.getUser();
					Random random = new Random();
					user.setNoOfLogin(random.nextInt(1234567));
					System.out.println(user.getFirstName() + "\t"
							+ user.getNoOfLogin() + "\t"
							+ Thread.currentThread().getName());
					try {
						Thread.sleep(random.nextInt(23456));
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		};

		// Here's where the other threads
		// are actually created
		for (int i = 0; i < 5; i++) {
			Thread t = new Thread(runner);
			t.start();
		}
	}
}
